local juyi = fk.CreateSkill{
  name = "gai__juyi",
  tags = { Skill.Limited },
}

Fk:loadTranslationTable{
  ["gai__juyi"] = "举义",
  [":gai__juyi"] = "限定技，准备阶段，若你体力上限大于存活角色数，你摸X张牌（X为你的体力上限），这些牌不计入你的手牌上限，然后获得技能〖崩坏〗。",

  ["@@juyi-inhand-permanent"] = "举义",

  ["$gai__juyi1"] = "司马氏，定不攻自败也。",
  ["$gai__juyi2"] = "义照淮流，身报国恩！",
}

juyi:addEffect(fk.EventPhaseStart, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(juyi.name) and player.phase == Player.Start and
      player:usedSkillTimes(juyi.name, Player.HistoryGame) == 0 and
      player.maxHp > #player.room.alive_players
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local drawNum = player.maxHp
    
    -- 摸牌并永久标记这些牌不计入手牌上限
    local cards = room:getNCards(drawNum)
    room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, juyi.name, nil, false, player, "@@juyi-inhand-permanent")
    
    -- 获得技能
    if not player.dead then
      room:handleAddLoseSkills(player, "benghuai")
    end
  end,
})

-- 添加手牌上限不计的效果
juyi:addEffect("maxcards", {
  exclude_from = function(self, player, card)
    return card:getMark("@@juyi-inhand-permanent") > 0
  end,
})

return juyi